package com.mk.sso.client.controller;

import com.mk.sso.boot.annotation.CurrentUser;
import com.mk.sso.sdk.beans.SsoUser;
import com.mk.sso.sdk.conf.SsoConf;
import com.mk.sso.sdk.util.SsoTokenLoginHelper;
import com.mk.sso.sdk.util.SsoUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;

@RestController
public class IndexController {


    @GetMapping("/getUser")
    public SsoUser getUser(HttpServletRequest request){
        String token = request.getHeader(SsoConf.TOKEN_AUTH_HEADER);
        if (StringUtils.isNotEmpty(token)) {
            return SsoTokenLoginHelper.getStorageUser(token);
        }
        return SsoUtil.getCurrentUser(request);
    }


    @GetMapping("/getCurrentUser")
    public SsoUser getCurrentUser(@CurrentUser SsoUser ssoUser){
        return ssoUser;
    }
}
